package thread;
//实现Runnable接口 重写run() 创建线程
class MyThread2 implements Runnable {//Runnable 可执行的
    @Override
    public void run() {
        while(true){
            System.out.println("runnable");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
public class ThreadCreate2 {
    public static void main(String[] args) {
//        Runnable runnable = new MyThread2();
//        Thread t = new Thread(runnable);该写法造成了线程与执行的任务解耦合
        Thread t = new Thread(new MyThread2());//创建一个新的线程，该线程的任务是由MyThread2类的实例定义的
        t.start();
        while(true){
            System.out.println("main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
